package com.hzbank.juc.introduction;

import lombok.extern.slf4j.Slf4j;

import java.sql.Time;
import java.util.concurrent.TimeUnit;

import static java.lang.Thread.sleep;

/**
 * @description:
 * @author: libugu@cskaoyan.com
 * @date 2023/12/18 - 19:13
 */
@Slf4j
public class Interrupt {

    public static void main(String[] args) throws InterruptedException {

        Thread t2 = new Thread(()->{
            while(true) {
                Thread current = Thread.currentThread();
                boolean interrupted = current.isInterrupted();
                if(interrupted) {
                    log.debug(" 打断状态: {}", interrupted);
                    break;
                }
            }
        }, "t2");
        t2.start();
        TimeUnit.SECONDS.sleep(1);
        t2.interrupt();
    }
}
